﻿using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Windows.Forms;
using Kugar.ERPFramework.Entity;

namespace Kugar.ERPFramework.View.WinForm
{
    [Designer(typeof(RMSEditorControlDesigner))]
    public class RMSDesigner : System.ComponentModel.Component
    {
        public RMSDesigner()
        {
            RMSList=new List<ControlRMSItem>();

        }

        public RMSDesigner(IContainer container)  :this()
        {  
            container.Add(this);  
 
        }  

        public override ISite Site
        {
            get
            {
                return base.Site;
            }
            set
            {
                if (base.Site != value)
                {
                    base.Site = value;
                    //使用反射机制，在设计时刻取得你要控制的窗体。  
                    IReferenceService referenceService = (IReferenceService)this.GetService(typeof(IReferenceService));
                    if (referenceService != null)
                    {
                        /**/
                        ///下面这句用于取得本组件所在的窗体对象。  
                        object[] parent = referenceService.GetReferences(typeof(Form));

                        Form container = parent[0] as Form;

                        //Form container = parent[0] as Form;
                        this.Form = container;
                        /**/
                        ///如下方法测试，可以知道parent.Length总是为1的。  
                        //StyleForm.Text = parent.Length.ToString();  
                    }
                }
            }
        }

        [Description("本组件所要控制的窗体"), DefaultValue(null)]
        public Form Form { get;
            set;
        }  

        [Localizable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [Editor(typeof(RMSEditorActionList.RMSEditorUITypeDesign), typeof(UITypeEditor))]
        [Browsable(false)]
        public IEnumerable<ControlRMSItem> RMSList { get; set; }
    }
}